/**
* This file is part of tictionary.
*
* tictionary is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with dev.clipall.  If not, see <http://www.gnu.org/licenses/>.
*
* http://code.google.com/p/tictionary/
*/

/*
 * Utils.java
 * Created on February 16, 2008, 3:43 PM
 */

package dicterator.dict.mobile;

import dicterator.Constants;


/**
 *
 * @author Erol Hira
 */
public class Utils implements Constants {
        
    public static byte getCharAsByte(char ch){
        
        for(int i = 0; i < chars.length; i++){
            String str = chars[i];
            if(str.charAt(0) == ch){
                return (byte) i;
            }
        }
        
        return -1;
    }    
    
    public static char getChar(byte b){
        
        String ch = chars[b];
        return ch.charAt(0);
    }
    
    public static byte[] string2bytes(String str){
        
        byte[] bytes = new byte[str.length()];
        
        for(int i = 0; i < bytes.length; i++){
            bytes[i] = getCharAsByte(str.charAt(i));
        }
        
        return bytes;
    }
    
    public static String bytes2string(byte[] bytes){
        
        StringBuffer buf = new StringBuffer();
        
        for(int i = 0; i < bytes.length; i++){
            buf.append(getChar(bytes[i]));
        }
        
        return buf.toString();
    }
    
    public static String getDictLetter(char ch, char ch2){                
        
        if(ch == c_cedilla.charAt(0)){
            return "cc";
        } else if(ch == i_diaresis.charAt(0)){
            return "ii";
        } else if(ch == o_diaresis.charAt(0)){
            return "oo";
        } else if(ch == s_cedilla.charAt(0)){
            return "ss";
        } else if(ch == u_diaresis.charAt(0)){
            return "uu";
        } else {
            StringBuffer buf = new StringBuffer();
            buf.append(ch);
            return buf.toString();
        }
    }
    
    public static String getDictFile(char ch, char ch2){
        return "out/".concat(getDictLetter(ch, ch2).concat(".dat"));
    }        
}
